import playerDataInfo from "./playerData";

const { ccclass, property } = cc._decorator;

@ccclass
export default class gameEnd extends cc.Component {
    @property(cc.Node)
    nodeWin: cc.Node = null;
    @property(cc.Node)
    nodeLose: cc.Node = null;
    @property(cc.Node)
    btnWin: cc.Node = null;
    @property(cc.Node)
    btnLose: cc.Node = null;
    @property(cc.Sprite)
    spPingJia: cc.Sprite = null;
    @property(cc.SpriteFrame)
    pingJiaArr: cc.SpriteFrame[] = [];
    @property(cc.Label)
    txtGetCoin: cc.Label = null;
    @property(cc.Label)
    txtAwardCoin: cc.Label = null;
    @property(cc.Label)
    txtAllCoin: cc.Label = null;
    @property(cc.Label)
    txtCoin: cc.Label = null;
    @property(cc.Label)
    txtTiLi: cc.Label = null;
    @property(cc.Label)
    txtLevel: cc.Label = null;

    onLoad() {
        this.initData();
    }

    initData() {
        //@ts-ignore
        this.txtCoin.string = playerDataInfo.gameData.coin;
        //@ts-ignore
        this.txtLevel.string = playerDataInfo.gameData.level;
        //@ts-ignore
        this.txtTiLi.string = playerDataInfo.gameData.tiLi;
        //根据状态显示胜利或者失败
        //@ts-ignore
        if (window.gameData.gameState == "win") {
            this.nodeLose.active = false;
            this.nodeWin.active = true;
            this.btnLose.active = false;
            this.btnWin.active = true;
        }
        else {
            this.nodeLose.active = true;
            this.nodeWin.active = false;
            this.btnLose.active = true;
            this.btnWin.active = false;
        }

        //@ts-ignore
        this.txtGetCoin.string = window.gameData.wipePlane
        //@ts-ignore
        this.txtAwardCoin.string = "300";
        this.txtAllCoin.string = String(Number(this.txtAwardCoin.string) + Number(this.txtGetCoin.string));

        let allCoin = Number(this.txtCoin.string) + Number(this.txtAllCoin.string)
        playerDataInfo.setGameDataByKey("coin", allCoin);
        //@ts-ignore
        if (window.gameData.gameState == "win") playerDataInfo.setGameDataByKey("level", Number(playerDataInfo.gameData.level) + 1);
        //@ts-ignore
        if (window.gameData.gameState == "win") playerDataInfo.setGameDataByKey("lifeNum", window.gameData.lifeNum);
        else playerDataInfo.setGameDataByKey("lifeNum", 3);
        //@ts-ignore
        playerDataInfo.setGameDataByKey("bulletType", window.gameData.bulletType);
        //@ts-ignore
        playerDataInfo.setGameDataByKey("bulletLevel", window.gameData.bulletLevel);
    }

    addEventListener() {

    }

    onButtonByGameStateCallback() {
        //@ts-ignore
        if (window.gameData.gameState == "win") {
            //
        }
        else {

        }
    }

    onButtonContinueCallback() {
        cc.director.loadScene("gameMain");
    }

    onButtonReturnCallback() {
        cc.director.loadScene("gameStart");
    }
}
